﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Threading;

namespace AzureDiagMon.Common.Mvvm
{
    public static class DispatcherHelper
    {
        private static Dispatcher dispatcher;

        static DispatcherHelper()
        {
#if SILVERLIGHT
            dispatcher = Deployment.Current.Dispatcher;
#else
            dispatcher = Dispatcher.CurrentDispatcher;
#endif
        }

#if !SILVERLIGHT
        public static void Initialize()
        {
            dispatcher = Dispatcher.CurrentDispatcher;
        }
#endif
        public static Dispatcher Current
        {
            get
            {
                return dispatcher;
            }
        }

        public static void Execute(Action action)
        {
            if (dispatcher.CheckAccess())
            {
                action();
            }
            else
            {
                dispatcher.BeginInvoke(action);
            }
        }
    }
}
